package com.rmb.controller;




import com.rmb.common.model.response.CommonCode;
import com.rmb.common.model.response.ResponseResult;
import com.rmb.mart.entity.userinfo.UserCompany;
import com.rmb.request.UserCompanyRequest;
import com.rmb.service.UserCompanyService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * (UserCompany)表控制层
 *
 * @author makejava
 * @since 2021-01-20 14:10:32
 */
@RestController
@RequestMapping("/business/management")
public class UserCompanyController {

    /**
     * 服务对象
     */
    @Resource
    private UserCompanyService userCompanyService;


    /**
     * 查询企业列表
     * @return list
     */
    @GetMapping("/findList")
    public List<UserCompany> findList(){
       return userCompanyService.findList();
    }

    /**
     * 添加企业
     * @return UserCompany
     */
    @PostMapping("/addBusiness")
    public UserCompany addBusiness(@RequestBody UserCompany userCompany){
        return userCompanyService.addBusiness(userCompany);
    }

    /**
     * 修改企业
     * @return UserCompany
     */
    @PutMapping("/updateBusiness")
    public UserCompany updateBusiness(@RequestBody UserCompany userCompany){
        return userCompanyService.updateBusiness(userCompany);
    }


    /**
     * 上传营业执照
     * @return String
     */
    @PostMapping("/uploadLicense")
    public String uploadLicense(MultipartFile file){
        return userCompanyService.uploadLicense(file);
    }


    /**
     * 删除企业
     * @return String
     */
    @DeleteMapping("/deleteBusiness/{id}")
    public UserCompany deleteBusiness(@PathVariable("id") Long id){
        return userCompanyService.deleteUserCompany(id);
    }


    /**
     * 根据状态查询企业
     * @param status
     * @return
     */
    @GetMapping("/findByStatus/{status}")
    public List<UserCompany> findByStatus(@PathVariable("status")Integer status){
        return userCompanyService.findByStatus(status);
    }

    /**
     * 审核失败更改状态并发送消息提示
     * @param userCompanyRequest
     * @return
     */
    @PutMapping("/auditFailed")
    public ResponseResult auditFailed(@RequestBody UserCompanyRequest userCompanyRequest){
        if (userCompanyService.auditFailed(userCompanyRequest)<=0){
            return new ResponseResult(CommonCode.FAIL);
        }
        return new ResponseResult(CommonCode.SUCCESS);
    }
}